package com.dongdongshop.mq;

import com.dongdongshop.common.AjaxResult;
import com.dongdongshop.common.ResultEnum;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("GV")
public class GenerateVerification {
    Logger logger = LoggerFactory.getLogger(GenerateVerification.class);
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /*发送验证码的手机号*/
    @RequestMapping("GenerateVerificationMQ")
    @ResponseBody
    public AjaxResult GenerateVerificationMQ(String phone){
        try {
            if (phone != null && !"".equals(phone)){
                rocketMQTemplate.convertAndSend("VERIFICATION",phone);
                System.out.println("我的验证码MQ!发送成功!");
                return AjaxResult.R(ResultEnum.SUCCESS);
            }
            return AjaxResult.R(ResultEnum.ERROR);
        }catch (Exception e){
            logger.error("商品审核失败!错误详情:{}",e);
            return AjaxResult.R(ResultEnum.ERROR);
        }
    }

}
